package com.lkd.service.impl;

import com.google.common.collect.Lists;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Strings;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyChannel;
import com.lkd.contract.SupplyContract;
import com.lkd.contract.TaskCompleteContract;
import com.lkd.dao.TaskDao;
import com.lkd.emq.MqttProducer;
import com.lkd.entity.TaskDetailsEntity;
import com.lkd.entity.TaskEntity;
import com.lkd.entity.TaskStatusTypeEntity;
import com.lkd.entity.TaskTypeEntity;
import com.lkd.exception.LogicException;
import com.lkd.feign.UserService;
import com.lkd.feign.VMService;
import com.lkd.http.controller.TaskController;
import com.lkd.http.vo.CancelTaskViewModel;
import com.lkd.http.vo.TaskReportInfoVO;
import com.lkd.http.vo.TaskStatusCollectVo;
import com.lkd.http.vo.TaskViewModel;
import com.lkd.service.TaskDetailsService;
import com.lkd.service.TaskService;
import com.lkd.service.TaskStatusTypeService;
import com.lkd.vo.Pager;
import com.lkd.vo.UserVO;
import com.lkd.vo.UserWorkVO;
import com.lkd.vo.VmVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.ConnectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.stream.Task;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class TaskServiceImpl extends ServiceImpl<TaskDao, TaskEntity> implements TaskService {

    @Autowired
    private TaskStatusTypeService statusTypeService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private VMService vmService;

    @Autowired
    private UserService userService;

    @Autowired
    private TaskDetailsService taskDetailsService;


    @Override
    public Pager<TaskEntity> search(Long pageIndex, Long pageSize, String innerCode, Integer userId, String taskCode, Integer status, Boolean isRepair, String start, String end) {
        Page<TaskEntity> page = new Page<>(pageIndex, pageSize);
        LambdaQueryWrapper<TaskEntity> qw = new LambdaQueryWrapper<>();
        if (!Strings.isNullOrEmpty(innerCode)) {
            qw.eq(TaskEntity::getInnerCode, innerCode);
        }
        if (userId != null && userId > 0) {
            qw.eq(TaskEntity::getUserId, userId);
        }
        if (!Strings.isNullOrEmpty(taskCode)) {
            qw.like(TaskEntity::getTaskCode, taskCode);
        }
        if (status != null && status > 0) {
            qw.eq(TaskEntity::getTaskStatus, status);
        }
        if (isRepair != null) {
            if (isRepair) {
                qw.ne(TaskEntity::getProductTypeId, VMSystem.TASK_TYPE_SUPPLY);
            } else {
                qw.eq(TaskEntity::getProductTypeId, VMSystem.TASK_TYPE_SUPPLY);
            }
        }
        if (!Strings.isNullOrEmpty(start) && !Strings.isNullOrEmpty(end)) {
            qw
                    .ge(TaskEntity::getCreateTime, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE))
                    .le(TaskEntity::getCreateTime, LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE));
        }
        //根据最后更新时间倒序排序
        qw.orderByDesc(TaskEntity::getUpdateTime);

        return Pager.build(this.page(page, qw));
    }


    @Override
    public List<TaskStatusTypeEntity> getAllStatus() {
        QueryWrapper<TaskStatusTypeEntity> qw = new QueryWrapper<>();
        qw.lambda()
                .ge(TaskStatusTypeEntity::getStatusId, VMSystem.TASK_STATUS_CREATE);

        return statusTypeService.list(qw);
    }

    @Autowired
    MqttProducer mqttProducer;

    /**
     * 创建工单
     *
     * @param taskViewModel
     * @return
     * @throws LogicException
     */
    @Transactional
    @Override
    public boolean createTask(TaskViewModel taskViewModel) throws LogicException {
        //跨服务查询售货机微服务，得到售货机的地址和区域id
        VmVO vm = vmService.getVMInfo(taskViewModel.getInnerCode());
        if (vm == null) {
            throw new LogicException("该机器不存在");
        }
        //跨服务查询用户微服务，得到用户名==>执行人
        Integer userId = taskViewModel.getUserId();
        UserVO user = userService.getUser(userId);
        if (user == null) {
            throw new LogicException("该用户不存在");
        }

        //TODO 校验售货机的状态与工单类型是否相符-
        int status = vm.getVmStatus();//售货机状态 0:未投放;1-运营;3-撤机
        if (VMSystem.TASK_TYPE_DEPLOY.equals(taskViewModel.getProductType()) && VMSystem.VM_STATUS_RUNNING.equals(status)) {//投放工单
            throw new LogicException("机器运营状态，工单类型不能为投放");
        }
        if (VMSystem.TASK_TYPE_SUPPLY.equals(taskViewModel.getProductType()) && !VMSystem.VM_STATUS_RUNNING.equals(status)) {//补货工单
            //不是运营状态
            throw new LogicException("机器非运营状态，工单类型不能为补货");
        }

        if (VMSystem.TASK_TYPE_REVOKE.equals(taskViewModel.getProductType()) && !VMSystem.VM_STATUS_RUNNING.equals(status)) {//撤机工单
            //不是运营状态
            throw new LogicException("机器非运营状态，工单类型不能为撤机！");
        }

        //查询当前机器的工单 是否有在进行中
        LambdaQueryWrapper<TaskEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(TaskEntity::getTaskId)
                .eq(TaskEntity::getInnerCode, taskViewModel.getInnerCode())
                .eq(TaskEntity::getProductTypeId, taskViewModel.getProductType())
                .le(TaskEntity::getTaskStatus, VMSystem.TASK_STATUS_PROGRESS);
        //.between(TaskEntity::getTaskStatus,VMSystem.TASK_STATUS_CREATE,VMSystem.TASK_STATUS_FINISH);

        TaskEntity entity = getOne(wrapper);
        if (entity != null) {
            throw new LogicException("机器非运营状态，工单类型不能为撤机！");
        }

        //新增工单表记录
        TaskEntity taskEntity = new TaskEntity();
        taskEntity.setTaskCode(generateTaskCode());//工单编号
        BeanUtils.copyProperties(taskViewModel, taskEntity);//复制属性
        taskEntity.setTaskStatus(VMSystem.TASK_STATUS_CREATE);//工单状态
        taskEntity.setProductTypeId(taskViewModel.getProductType());//工单类型

        taskEntity.setAddr(vm.getNodeAddr());//地址
        taskEntity.setRegionId(vm.getRegionId());//区域
        taskEntity.setUserName(user.getUserName());//用户名
        this.save(taskEntity);

        //如果是补货工单，向 工单明细表插入记录
        if (taskEntity.getProductTypeId() == VMSystem.TASK_TYPE_SUPPLY) {
            taskViewModel.getDetails().forEach(d -> {
                TaskDetailsEntity detailsEntity = new TaskDetailsEntity();
                BeanUtils.copyProperties(d, detailsEntity);
                detailsEntity.setTaskId(taskEntity.getTaskId());
                taskDetailsService.save(detailsEntity);
            });
        }
        //对当日对应的人员工单数量更新
        taskUpdateNum(taskEntity, 1);

        return true;
    }

    /**
     * 更新redis的工单数量
     *
     * @param taskEntity
     * @param score
     */
    private void taskUpdateNum(TaskEntity taskEntity, int score) {
        //判断当前工单的类型 对需要的人员的类型进行修改
        String code = "1003";//默认维修员
        if (taskEntity.getProductTypeId().equals(VMSystem.TASK_TYPE_SUPPLY)) {
            code = "1002";//运营员
        }
        //拼接key值 对当天的单数进行修改
        String key = VMSystem.REGION_TASK_KEY_PREF +
                LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "."
                + taskEntity.getRegionId() + "." + code;
        //实现数据的原自增
        redisTemplate.opsForZSet().incrementScore(key, taskEntity.getUserId(), score);
    }

    /**
     * 获取当日工单数量最少的人员
     *
     * @param regionId
     * @param flag
     * @return
     */
    @Override
    public int getLeastTsakUser(Long regionId, boolean flag) {
        String code = "1002";
        //根据boolen的参数判断是那种类型人员
        if (flag) {
            code = "1003";
        }
        String key = VMSystem.REGION_TASK_KEY_PREF +
                LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "."
                + regionId + "." + code;
        Set<Object> set = redisTemplate.opsForZSet().range(key, 0, 0);
        //判断工单最少人员为不为空
        if (set == null) {
            return 0;//数据不存在
        }
        return (int) set.stream().collect(Collectors.toList()).get(0);
    }

    /**
     * 生成工单编号
     *
     * @return
     */
    private String generateTaskCode() {
        //日期+序号
        String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));  //日期字符串
        String key = "lkd.task.code." + date; //redis key
        Object obj = redisTemplate.opsForValue().get(key);
        if (obj == null) {
            redisTemplate.opsForValue().set(key, 1L, Duration.ofDays(1));
            return date + "0001";
        }       //根据Strings.padStart从左侧填充长度为4  //如果不为空 获取之前redis存入的订单的值进行递增
        return date + Strings.padStart(redisTemplate.opsForValue().increment(key, 1).toString(), 4, '0');
    }


    @Override
    public boolean accept(Long id, Integer userId) {
        TaskEntity task = this.getById(id);  //查询工单
        if (!userId.equals(task.getUserId())) {
            throw new LogicException("当前工单只能当前用户接收");
        }
        //TODO 判断订单是否存在 判断状态是创建的状态才能被接受
        if (!task.getTaskStatus().equals(VMSystem.TASK_STATUS_CREATE)) {
            throw new LogicException("工单不是未处理状态");
        }
        task.setTaskStatus(VMSystem.TASK_STATUS_PROGRESS);//修改工单状态为进行
        return this.updateById(task);
    }

    @Override
    public boolean cancelTask(Long id, CancelTaskViewModel cancelVM, Integer userId) {
        TaskEntity task = this.getById(id);  //查询工单
        //TODO 工单判空 判断订单是否已经完成已取消
        if (!(userId.equals(task.getUserId()) || task.getAssignorId().equals(userId))) {//当前为用户登录 或者指派人登录
            throw new LogicException("当前工单只能当前用户或指派人取消");
        }
        TaskEntity taskEntity = getOne(Wrappers.<TaskEntity>lambdaQuery().eq(TaskEntity::getTaskId, id));
        if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_CANCEL) || taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_FINISH)) {
            throw new LogicException("工单已经被取消或已完成");
        }
        task.setTaskStatus(VMSystem.TASK_STATUS_CANCEL);
        task.setDesc(cancelVM.getDesc());
        taskUpdateNum(taskEntity, -1);
        return this.updateById(task);
    }

    @Override
    public boolean completeTask(long id, Integer userId) {
        TaskEntity taskEntity = this.getById(id);
        if (!userId.equals(taskEntity.getUserId())) {
            throw new LogicException("当前工单只能当前用户点击完成");
        }
        //TODO 判空 判断工单是进行状态
        if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_CANCEL) || taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_FINISH)) {
            throw new LogicException("工单已经被取消或已完成");
        }
        taskEntity.setTaskStatus(VMSystem.TASK_STATUS_FINISH);//修改工单状态
        this.updateById(taskEntity);
        //TODO 运维工单发送消息==>投放 撤机
        if (taskEntity.getProductTypeId().equals(VMSystem.TASK_TYPE_DEPLOY) || taskEntity.getProductTypeId().equals(VMSystem.TASK_TYPE_REVOKE)) {//投放工单
            //发送投放工单的参数信息
            sendMsg(taskEntity.getInnerCode(), taskEntity.getProductTypeId());
        }
        //TODO 补货工单
        if (taskEntity.getProductTypeId().equals(VMSystem.TASK_TYPE_SUPPLY)) {
            sendSupplyMsg(taskEntity);
        }
        return true;
    }

    /**
     * 补货信息EMQ发送
     *
     * @param taskEntity
     */
    private void sendSupplyMsg(TaskEntity taskEntity) {
        //创建协议类
        SupplyContract supplyContract = new SupplyContract();
        ArrayList<SupplyChannel> supplyChannels = new ArrayList<>();
        //补货单所有商品细节的集合
        List<TaskDetailsEntity> list = taskDetailsService.getByTaskId(taskEntity.getTaskId());
        if (CollectionUtils.isEmpty(list)) {
            throw new LogicException("补货信息不能为空");
        }
        list.forEach(taskDetailsEntity -> {
            SupplyChannel supplyChannel = new SupplyChannel();
            supplyChannel.setChannelId(taskDetailsEntity.getChannelCode());
            supplyChannel.setCapacity(taskDetailsEntity.getExpectCapacity());//容量
            supplyChannel.setSkuId(taskDetailsEntity.getSkuId());//商品编号
            supplyChannel.setSkuName(taskDetailsEntity.getSkuName());//商品名字
            supplyChannel.setSkuImage(taskDetailsEntity.getSkuImage());//商品名字
            supplyChannels.add(supplyChannel);
        });
        //补货商品集合
        supplyContract.setSupplyData(supplyChannels);
        //机器码
        supplyContract.setInnerCode(taskEntity.getInnerCode());
        //EMQ发送消息
        try {
            mqttProducer.send(TopicConfig.VMS_SUPPLY_TOPIC, 2, supplyContract);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

    }

    /**
     * EMQ发送消息
     */
    private void sendMsg(String innerCode, Integer taskType) {
        //封装需要的机器码 和工单类型
        TaskCompleteContract taskCompleteContract = new TaskCompleteContract();
        taskCompleteContract.setTaskType(taskType);
        taskCompleteContract.setInnerCode(innerCode);
        //EMQ发送消息
        try {
            mqttProducer.send(TopicConfig.VMS_COMPLETED_TOPIC, 2, taskCompleteContract);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }

    /**
     * 人效统计
     *
     * @param start
     * @param end
     * @return
     */
    @Autowired
    TaskDao taskDao;


    public List<TaskEntity> getByTime(String start, String end) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime str = LocalDateTime.parse(start, df);
        LocalDateTime en = LocalDateTime.parse(end, df);
        return list(Wrappers.<TaskEntity>lambdaQuery().between(TaskEntity::getUpdateTime, str, en));
    }

    @Override
    public List<TaskReportInfoVO> humanEffect(String start, String end) {
        //运营人员人数
        Integer operatorCount = userService.getOperatorCount();
        //运维人员人数
        Integer repairerCount = userService.getRepairerCount();
        //时间查询
        List<TaskEntity> taskList = getByTime(start, end);
        /*List<TaskEntity> taskList = new ArrayList<>();
        try {
            Date st = new SimpleDateFormat().parse(start);
            Date en = new SimpleDateFormat().parse(end);
            taskList = taskDao.getByTime(st,en);
        } catch (ParseException e) {
            e.printStackTrace();
        }*/
        if (CollectionUtils.isEmpty(taskList)) {
            log.info("taskList集合为空");

        }
        //2.创建封装数据的集合
        ArrayList<TaskReportInfoVO> respList = new ArrayList<>();
        //运营
        TaskReportInfoVO infoOperation = new TaskReportInfoVO();
      /*  List<Integer> operationlist = taskList.stream().filter(a->a.getTaskType().getType()==2)
                .map(TaskEntity::getUserId).distinct().collect(Collectors.toList());*/
        //运营工作人数
        infoOperation.setWorkerCount(operatorCount);
        //不是运维工单的统计
        infoOperation.setRepair(false);
        infoOperation.setDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")));
        infoOperation.setTotal(0);
        infoOperation.setCompletedTotal(0);
        infoOperation.setCancelTotal(0);
        infoOperation.setProgressTotal(0);
        //运维
        TaskReportInfoVO infoRepairer = new TaskReportInfoVO();
        //工作人数
        infoRepairer.setWorkerCount(repairerCount);
        //是运维工单的统计
        infoRepairer.setRepair(true);
        infoRepairer.setDate(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss")));
        infoRepairer.setTotal(0);
        infoRepairer.setCompletedTotal(0);
        infoRepairer.setCancelTotal(0);
        infoRepairer.setProgressTotal(0);
        //2.1数据处理分为运维人员和运营人员
        /*      for (TaskEntity taskEntity : taskList) {*/
        taskList.forEach(taskEntity -> {
            //运维
            if (taskEntity.getTaskType().getType() == 1) {
                infoOperation.setTotal(infoOperation.getTotal() + 1);
                //完成计数
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_FINISH)) {
                    infoOperation.setCompletedTotal(infoOperation.getCompletedTotal() + 1);
                }
                //取消计数
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_CANCEL)) {
                    infoOperation.setCancelTotal(infoOperation.getCancelTotal() + 1);
                }
                //进行计数
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_PROGRESS)) {
                    infoOperation.setProgressTotal(infoOperation.getProgressTotal() + 1);
                }

            } else if (taskEntity.getTaskType().getType() == 2) {
                //运营
                infoRepairer.setTotal(infoRepairer.getTotal() + 1);
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_FINISH)) {
                    infoRepairer.setCompletedTotal(infoRepairer.getCompletedTotal() + 1);
                }
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_CANCEL)) {
                    infoRepairer.setCancelTotal(infoRepairer.getCancelTotal() + 1);
                }
                if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_PROGRESS)) {
                    infoRepairer.setProgressTotal(infoRepairer.getProgressTotal() + 1);
                }
            }
        });
        /*  };*/
        Collections.addAll(respList, infoOperation, infoRepairer);
        return respList;
    }

    public List<TaskEntity> getByTime(LocalDate start, LocalDate end, Integer status,Integer regionId, Boolean isRepair) {
        LambdaQueryWrapper<TaskEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TaskEntity::getTaskStatus,status);
      //  int type;
        if (isRepair){//是运维
            wrapper.ne(TaskEntity::getProductTypeId,VMSystem.TASK_TYPE_SUPPLY);
        }else {
            wrapper.eq(TaskEntity::getProductTypeId,VMSystem.TASK_TYPE_SUPPLY);
        }
       // wrapper.eq(TaskEntity::getTaskType,type);
        //地区
        if (regionId != 0) {
            wrapper.eq(TaskEntity::getRegionId,regionId);
        }
        //时间
        wrapper.between(TaskEntity::getUpdateTime,start,end);
        List<TaskEntity> list = this.list(wrapper);
        System.out.println();
        return list;
    }


    /**
     * 人员工作量列表
     *
     * @param start
     * @param end
     * @return
     */
    @Override
    public List<UserWorkVO> userWorkVOList(LocalDate start, LocalDate end, Integer regionId, Boolean isRepair) {
        //1.参数校验
        if (start == null || end == null) {
            throw new LogicException("时间参数不能为空");
        }
        //时间查询 完成的工单
        List<TaskEntity> taskEntityList = getByTime(start, end, VMSystem.TASK_TYPE_REVOKE,regionId,isRepair);
        taskEntityList.stream().collect(Collectors.groupingBy(taskEntity ->
            taskEntity.getUpdateTime().toLocalDate()));
        //2.创建封装数据的集合
        ArrayList<UserWorkVO> workVOArrayList = new ArrayList<>();
        //3.封装数据
        //分组完成
        Map<String, List<TaskEntity>> map = taskEntityList.stream().collect(Collectors.groupingBy(TaskEntity::getUserName));
        //将对应用户的工单进行数据封装
        map.forEach((name,list)->{
            UserWorkVO userWorkVO = new UserWorkVO();
            userWorkVO.setUserName(name);
            userWorkVO.setWorkCount(list.size());
            workVOArrayList.add(userWorkVO);
        });
        //taskEntityList.stream().collect(Collectors.groupingBy(TaskEntity::getUpdateTime));

       /* Map<String, List<PointsLogEntity>> dataTimePointLog = pointsLogEntityList
                .stream().collect(Collectors.groupingBy(item -> new SimpleDateFormat("yyyy-MM-dd")
                        .format(new Date(item.getTime()))));*/
        return workVOArrayList.stream().sorted(Comparator.comparing(UserWorkVO::getWorkCount).reversed()).limit(10).collect(Collectors.toList());
    }


    /**
     * 统计订单状态
     * @param start
     * @param end
     * @return
     */
/*    @Override
    public List<TaskStatusCollectVo> getTaskStatus(LocalDate start, LocalDate end) {
        //获取集合
        // Map<String, List<PointsLogEntity>> dataTimePointLog = pointsLogEntityList.stream().collect(Collectors.groupingBy(item -> new SimpleDateFormat("yyyy-MM-dd").format(new Date(item.getTime()))));
        List<TaskEntity> taskEntityList = list(Wrappers.<TaskEntity>lambdaQuery().between(TaskEntity::getUpdateTime, start, end));
        taskEntityList.stream().collect(Collectors.groupingBy(item -> new SimpleDateFormat("yyyy-MM-dd").format(new Date(item::up))));

    }*/
    @Override
    public List<TaskStatusCollectVo> getTaskStatus(LocalDate start, LocalDate end) {
        //创建封装集合
        ArrayList<TaskStatusCollectVo> volist = new ArrayList<>();
        //遍历每天的日期 || currentdate.isEqual(end);
         /*  DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
     LocalDate startDate = LocalDate.parse(startTime, formatter);
        LocalDate endDate = LocalDate.parse(endTime, formatter);
        for(LocalDate currentdate = startDate; currentdate.isBefore(endDate) || currentdate.isEqual(endDate); currentdate= currentdate.plusDays(1)){
        System.out.println(currentdate);
    }*/
for(LocalDate currentdate = start; currentdate.isBefore(end) || currentdate.isEqual(start); currentdate= currentdate.plusDays(1)){
            //获取工单数量
            TaskStatusCollectVo vo = getvoCollect(currentdate);
            volist.add(vo);
        }
        return volist;
    }
    //获取每天的订单
    private TaskStatusCollectVo getvoCollect(LocalDate currentdate) {
        LocalDate end = currentdate.plusDays(1);
        //根据时间查询所有订单
        List<TaskEntity> taskEntityList = list(Wrappers.<TaskEntity>lambdaQuery().between(TaskEntity::getUpdateTime,currentdate,end));
        TaskStatusCollectVo vo = new TaskStatusCollectVo();
        vo.setFinishCount(0);
        vo.setProgressCount(0);
        vo.setCancelCount(0);
        String date = currentdate.format(DateTimeFormatter.ofPattern("MM-dd"));
        vo.setCollectDate(date);
        //遍历当日集合
        taskEntityList.forEach(taskEntity -> {
            if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_FINISH)){
                vo.setFinishCount(vo.getFinishCount() + 1);
            }
            if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_PROGRESS)){
                vo.setProgressCount(vo.getProgressCount() + 1);
            }
            if (taskEntity.getTaskStatus().equals(VMSystem.TASK_STATUS_CANCEL)){
                vo.setCancelCount(vo.getCancelCount() + 1);
            }
        });
        return vo;
    }
}
